package com.jh.user.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

/**
 * 快银支付通道-个人费率
 */
@Entity
@Table(name = "t_congming_rate")
public class CongMingRate implements Serializable {
    private static final long serialVersionUID = 1471054767659824177L;

    @Id
    @Column(name = "id")
    private long id;

    /**
     * userId
     */
    @Column(name = "user_id")
    private long userId;

    /**
     * 贴牌id
     */
    @Column(name = "brand_id")
    private long brandId;

    /**
     * 通道标识
     */
    @Column(name = "channel_tag")
    private String channelTag;

    /**
     * 个人费率
     */
    @Column(name = "rate")
    private BigDecimal rate = BigDecimal.ZERO;

    /**
     * 用户通道是否可用，1：可用，2：不可用
     */
    @Column(name = "status")
    private String status;

    @Column(name = "update_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @Column(name = "create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getBrandId() {
        return brandId;
    }

    public void setBrandId(long brandId) {
        this.brandId = brandId;
    }

    public String getChannelTag() {
        return channelTag;
    }

    public void setChannelTag(String channelTag) {
        this.channelTag = channelTag;
    }

    public BigDecimal getRate() {
        return rate;
    }

    public void setRate(BigDecimal rate) {
        this.rate = rate;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CongMingRate)) return false;
        CongMingRate that = (CongMingRate) o;
        return getId() == that.getId() &&
                getUserId() == that.getUserId() &&
                getBrandId() == that.getBrandId() &&
                getChannelTag() == that.getChannelTag() &&
                Objects.equals(getRate(), that.getRate()) &&
                Objects.equals(getStatus(), that.getStatus()) &&
                Objects.equals(getUpdateTime(), that.getUpdateTime()) &&
                Objects.equals(getCreateTime(), that.getCreateTime());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getUserId(), getBrandId(), getChannelTag(), getRate(), getStatus(), getUpdateTime(), getCreateTime());
    }

    @Override
    public String toString() {
        return "CongMingRate{" +
                "id=" + id +
                ", userId=" + userId +
                ", brandId=" + brandId +
                ", channelTag=" + channelTag +
                ", rate=" + rate +
                ", status='" + status + '\'' +
                ", updateTime=" + updateTime +
                ", createTime=" + createTime +
                '}';
    }

    public void addCongMingRate(CongMingChannel congMingChannel, long userId, long brandId) {
        setUserId(userId);
        setBrandId(brandId);
        setChannelTag(congMingChannel.getChannelTag());
        setRate(congMingChannel.getRate());
        setStatus(congMingChannel.getStatus());
        setUpdateTime(Calendar.getInstance().getTime());
        setCreateTime(Calendar.getInstance().getTime());
    }
}
